package com.zlzlib.mybatis;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.plugins.pagination.PageDTO;
import com.github.yulichang.base.MPJBaseMapper;

/**
 * @DateTime: 2023/2/24 9:08
 * @Author zlz
 * @Version 1.0
 */
public interface MyBaseMapper<T> extends MPJBaseMapper<T> {
    /**
     * 处理查询出来多个的异常
     *
     * @param queryWrapper 条件
     * @return 结果
     */
    @Override
    default T selectOne(Wrapper<T> queryWrapper) {
        PageDTO<T> dto = new PageDTO<>(1, 1);
        dto.setSearchCount(false);
        Page<T> page = this.selectPage(dto, queryWrapper);
        if (page.getRecords().isEmpty()) {
            return null;
        }
        return page.getRecords().get(0);
    }
}
